package 网络.TCP;

import java.io.*;
import java.net.ServerSocket;
import java.net.Socket;
@SuppressWarnings("all")
public class server01字符流 {
    public static void main(String[] args) throws IOException {
        ServerSocket serverSocket = new ServerSocket(8888);
        Socket socket = serverSocket.accept();
        InputStream inputStream = socket.getInputStream();
        //将读取的字节流转换成字符流
        BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(inputStream));
        String  data = null;
        while ((data = bufferedReader.readLine()) != null){
            System.out.println(data);
        }
        OutputStream outputStream = socket.getOutputStream();
        BufferedWriter bufferedWriter = new BufferedWriter(new OutputStreamWriter(outputStream));
        bufferedWriter.write("hello client");
        bufferedWriter.flush();
        bufferedWriter.newLine();

        bufferedWriter.close();
        bufferedReader.close();
        socket.close();
        serverSocket.close();
        System.out.println("服务单退出");
    }
}
